package com.mmall.concurrency.example.singleton;

import com.mmall.concurrency.annotions.ThreadSafes;

/**
 * 饿汉模式
 * 单例实例在类装载时进行创建
 *
 * @author Diamon.Cheng
 * @date 2019/12/5.
 */
@ThreadSafes
public class SingletonExample_6 {
    
    // 私有构造函数
    private  SingletonExample_6(){}
    
    // 单例对象
    public static  SingletonExample_6 instance = null;
    
    static {
        instance = new SingletonExample_6();
    }
    
    // 静态的工厂方法
    public  static SingletonExample_6 getInstance(){
        return  instance;
    }
    
    
    public static void main(String[] args) {
        System.out.println(getInstance().hashCode());
        System.out.println(getInstance().hashCode());
    }
}
